<html>
<head>
    <meta charset="UTF-8">
    <title>订单</title>
    <link href="./css/merchant.css" rel="stylesheet" type="text/css"/>
    <script language="JavaScript"
            src="http://libs.baidu.com/jquery/2.0.0/jquery.js"></script>
    <script language="JavaScript" src="./js/bootstrap.js"></script>
    <script language="javascript" src="./js/jquery.uploadifive.min.js"></script>
    <script src="client_modules/angular/angular.js"></script>
    <link rel="stylesheet" type="text/css" href="./css/bootstrap.css"/>
    <link rel="stylesheet" type="text/css" href="./css/add_dish.css"/>
    <link rel="stylesheet" type="text/css" href="./css/normalize.css"/>
    <link rel="stylesheet" type="text/css" href="./css/demo.css"/>
    <link rel="stylesheet" type="text/css" href="./css/icons.css"/>
    <link rel="stylesheet" type="text/css" href="./css/component.css"/>
    <link rel="stylesheet" type="text/css" href="./css/head.css"/>
    <script src="client_modules/ng-file-upload/ng-file-upload-all.js"></script>
    <script src="client_modules/ng-file-upload/ng-file-upload-shim.js"></script>

</head>


<body ng-app="addDish" style="background: #F3EFE0">

<ul id="nav">
    <li><img src="http://10.222.232.168:83/img/logo.png" class="logo"/></li>
    <li><a href="dishManager.html#/">菜单管理</a></li>
    <li><a href="dishManager.html#/orderManager">订单管理</a></li>
    <li><a href="dishManager.html#/historyOrder">历史订单</a></li>
    <li><a href="dishManager.html#/merchantMsg">商家信息</a></li>
    <li><a href="merchant">注销</a></li>
</ul>


<div class="dish" ng-controller="add">

    <form enctype="multipart/form-data" class="bootstrap-frm">
        <table>
            <tr>
                <td><label>菜名</label></td>
                <td><input type="text" name="dname" id="dname"></td>
            </tr>
            <tr>
                <td><label>价格</label></td>
                <td><input type="number" name="price" id="price"></td>
            </tr>
            <tr>
                <td><label>图片</label></td>
                <td>
                    <div>
                        <button class="uploadBtn" type="file"
                                ngf-select="uploadFiles($file, $invalidFiles)"
                                accept="image/*" ngf-max-height="1000" ngf-max-size="10MB">
                            选择图片
                        </button>
                        <div style="font:smaller">{{f.name}} {{errFile.name}} {{errFile.$error}}
                            {{errFile.$errorParam}}
                            <span class="progress" ng-show="f.progress >= 0">
                                                    <div style="width:{{f.progress}}%" ng-bind="f.progress + '%'"></div>
                                                </span>
                        </div>
                    </div>
                </td>
            </tr>
            <tr>
                <td colspan="2"><input type="button" id="addDishBtn" ng-click="addBtn()"
                                       value="添加菜品" class="button"></td>
            </tr>
        </table>
    </form>

</div>

</body>
<script type="text/javascript">

    angular.module('addDish', ['ngFileUpload'])
            .controller('add', ['$scope', 'Upload', '$timeout', '$http', function ($scope, Upload, $timeout, $http) {

                $scope.uploadFiles = function (file, errFiles) {
                    $scope.f = file;
                    $scope.errFile = errFiles && errFiles[0];
                    if (file) {
                        file.upload = Upload.upload({
                            url: 'upload',
                            data: {file: file}
                        });

                        file.upload.then(function (response) {
                            $timeout(function () {
                                file.result = response.data;
                            });
                        }, function (response) {
                            if (response.status > 0)
                                $scope.errorMsg = response.status + ': ' + response.data;
                        }, function (evt) {

                            file.progress = Math.min(100, parseInt(100.0 *
                                    evt.loaded / evt.total));
                        });
                    }
                }

                $scope.addBtn = function () {
                    var dname = document.getElementById('dname').value;
                    var price = document.getElementById('price').value;
                    var dicon = $scope.f.name;
                    var req = {
                        method: "POST",
                        url: "dish",
                        data: {dname: dname, price: price, dicon: dicon, recommend: 0},
                        headers: {"Content-type": "application/json"}
                    };
                    $http(req).then(function (res) {
                        if (!res.data.error) {
                            location.href = 'dishManager.html'
                        }
                    });
                }


            }]);
</script>
</html>









